package com.aipp.mall.wechat;

import com.wechat.pay.java.core.Config;
import com.wechat.pay.java.core.RSAAutoCertificateConfig;
import org.dromara.hutool.extra.spring.SpringUtil;

/**
 * @author cc
 */
public class WechatPayConfig {

    private static Config wechatPayConfig;

    private WechatPayConfig() {
    }

    public static Config getInstance() {

        WechatPayData wechatPayData = SpringUtil.getBean(WechatPayData.class);
        if (wechatPayConfig == null) {
            wechatPayConfig = new RSAAutoCertificateConfig.Builder()
                    .merchantId(wechatPayData.getMerchantId())
                    .privateKeyFromPath(wechatPayData.getPrivateKeyPath())
                    .merchantSerialNumber(wechatPayData.getMerchantSerialNumber())
                    .apiV3Key(wechatPayData.getApiV3key())
                    .build();
        }
        return wechatPayConfig;
    }
}
